/*
 * ImportSources module for Netbeans.
 *
 * Copyright (c) 2007, Rogue
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * For queries or bugs, you may contact me via e-mail: roguexz [at] gmail [dot] com
 */
package rogue.netbeans.module.importsources;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;

/**
 * Base wizard panel for this module. It contains a collection of useful methods
 * which help controlling the user flow through the wizard.
 *
 * @author Rogue.
 */
public abstract class AbstractWizardPanel implements WizardDescriptor.Panel {
    
    private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1);
    
    /**
     * Get the default help context.
     */
    public HelpCtx getHelp() {
        return HelpCtx.DEFAULT_HELP;
    }
    
    /**
     * Add a change listener for this wizard panel.
     */
    public final void addChangeListener(ChangeListener l) {
        synchronized (listeners) {
            listeners.add(l);
        }
    }
    
    /**
     * Remove a change listener from this wizard panel.
     */
    public final void removeChangeListener(ChangeListener l) {
        synchronized (listeners) {
            listeners.remove(l);
        }
    }
    
    /**
     * Fires a change event.
     */
    protected final void fireChangeEvent() {
        Iterator<ChangeListener> itr;
        synchronized (listeners) {
            itr = new HashSet<ChangeListener>(listeners).iterator();
        }
        ChangeEvent ev = new ChangeEvent(this);
        while (itr.hasNext()) {
            itr.next().stateChanged(ev);
        }
    }
    
    /**
     * Specifies if the current panel has completed processing or not.
     */
    public abstract boolean isPanelProcessingComplete();
    
    /**
     * Terminate any processing in the panel.
     */
    public abstract void terminateProcessing();
    
}

